package com.kkyy.findmusic.controller;

import com.kkyy.common.utils.R;
import com.kkyy.findmusic.entity.PlayEntity;
import com.kkyy.findmusic.entity.SongsEntity;
import com.kkyy.findmusic.service.PlayService;
import com.kkyy.findmusic.service.SongsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/findmusic")
public class SongsController {
    @Autowired
    private SongsService songsService;

    @Autowired
    private PlayService playService;

    // 查询歌单(前端)
    @RequestMapping("/songs")
    public R getSongs() {
        List<SongsEntity> songs = songsService.getSongs2();
        return R.ok().put("data", songs);
    }

    // 远程调用查询音乐(后台)
    @RequestMapping("/songs2")
    public List<SongsEntity> getSongs2() {
        List<SongsEntity> songs = songsService.getSongs();
        return songs;
    }

    // 点击播放
    @RequestMapping("/play")
    public R playMusic(Integer id) {
        PlayEntity playMusic = playService.playMusic(id);
        SongsEntity song = songsService.getOneById(playMusic.getSongsId());
        return R.ok().put("data", song);
    }

    // 远程调用删除最新音乐
    @RequestMapping("/songdel")
    public void delSongById(@RequestParam("id") Integer id) {
        songsService.delSongById(id);
    }

    // 远程调用下架最新音乐
    @RequestMapping("/downSong")
    void downSongById(@RequestParam("id") Integer id) {
        songsService.downSongById(id);
    }

    // 远程调用上架最新音乐
    @RequestMapping("/upSong")
    void upSongById(@RequestParam("id") Integer id) {
        songsService.upSongById(id);
    }

    @RequestMapping(value = "/addSongInfo", method = RequestMethod.GET)
    void addSongInfo(
            @RequestParam("songname") String songname,
            @RequestParam("songart") String songart,
            @RequestParam("picurl") String picurl,
            @RequestParam("location") Integer location) {
        songsService.addSongInfo(songname, songart, picurl, location);
    }
}